package cuilitang.hadoop.mapreduce;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 累加求和并输出
 */
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    int sum;
    IntWritable  valueOut= new IntWritable();

    @Override
    protected void reduce(Text keyin,
                          Iterable<IntWritable> valuesin,
                          Reducer<Text, IntWritable, Text, IntWritable>.Context context
    ) throws IOException, InterruptedException {


        for (IntWritable valueIn: valuesin) {
            sum+= valueIn.get();
        }
        valueOut.set(sum);
        context.write(keyin,valueOut);

        sum = 0;





    }
}
